package com.qf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.DtsCategory;
import com.qf.vo.CatVo;
import com.qf.vo.CategorySellAmts;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 类目表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
@Mapper
public interface DtsCategoryMapper extends BaseMapper<DtsCategory> {

    @Select("        SELECT\n" +
            "            dc.NAME,\n" +
            "            sum( dog.number * dog.price ) AS value\n" +
            "        FROM\n" +
            "            dts_category dc\n" +
            "                INNER JOIN dts_goods dg ON dc.id = dg.category_id\n" +
            "                INNER JOIN dts_goods_product dgp ON dg.id = dgp.goods_id\n" +
            "                INNER JOIN dts_order_goods dog ON dgp.id = dog.product_id\n" +
            "        GROUP BY\n" +
            "            dc.NAME")
    List<CategorySellAmts> findGoodsCategoryAndTotal();

    @Select("SELECT id value ,`name` label FROM `dts_category`")
    List<CatVo> L1List();

    @Update("UPDATE `dts_category` SET `deleted`=1 WHERE `id`=#{id}")
    void deleteUpdateById(Integer id);
}
